package cn.yuanqiao.web.controller.archive.storeRoom;

import cn.yuanqiao.archive.storeRoom.domain.UpDownLogs;
import cn.yuanqiao.archive.storeRoom.service.IUpDownLogsService;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.web.page.TableDataInfo;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * 上下架日志Controller
 * 
 * @author xy
 * @date 2023-06-30
 */
@RestController
@RequestMapping("/archive/UpDownLogs")
public class UpDownLogsController extends BaseController
{
    @Autowired
    private IUpDownLogsService upDownLogsService;

    /**
     * 查询上下架日志列表
     */
  /*  @PreAuthorize("@ss.hasPermi('storeroom:UpDownLogs:list')")*/
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:upDownRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(UpDownLogs upDownLogs) throws ParseException {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf1=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        startPage();
        if(upDownLogs.getEdCreateTime()!=null){
            upDownLogs.setEdCreateTime(sdf1.parse(sdf.format(upDownLogs.getEdCreateTime())+" 23:59:59"));

        }

        List<UpDownLogs> list = upDownLogsService.selectUpDownLogsList(upDownLogs);
        return getDataTable(list);
    }

    /**
     * 导出上下架日志列表
     */
    @PreAuthorize("@ss.hasPermi('storeroom:UpDownLogs:export')")
    @Log(title = "上下架日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UpDownLogs upDownLogs)
    {
        List<UpDownLogs> list = upDownLogsService.selectUpDownLogsList(upDownLogs);
        ExcelUtil<UpDownLogs> util = new ExcelUtil<UpDownLogs>(UpDownLogs.class);
        util.exportExcel(response, list, "上下架日志数据");
    }

    /**
     * 获取上下架日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('storeroom:UpDownLogs:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(upDownLogsService.selectUpDownLogsById(id));
    }

    /**
     * 新增上下架日志
     */
    @PreAuthorize("@ss.hasPermi('storeroom:UpDownLogs:add')")
    @Log(title = "上下架日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UpDownLogs upDownLogs)
    {
        return toAjax(upDownLogsService.insertUpDownLogs(upDownLogs));
    }

    /**
     * 修改上下架日志
     */
    @PreAuthorize("@ss.hasPermi('storeroom:UpDownLogs:edit')")
    @Log(title = "上下架日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UpDownLogs upDownLogs)
    {
        return toAjax(upDownLogsService.updateUpDownLogs(upDownLogs));
    }

    /**
     * 删除上下架日志
     */
    @PreAuthorize("@ss.hasPermi('storeroom:UpDownLogs:remove')")
    @Log(title = "上下架日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(upDownLogsService.deleteUpDownLogsByIds(ids));
    }
}
